<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scid" label="下级SCID，用于标识所属的监控中心">
          <a-input placeholder="请输入下级SCID，用于标识所属的监控中心" v-model="model.scid" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="siteid" label="站点编号，用于标识信号所在的站点">
          <a-input placeholder="请输入站点编号，用于标识信号所在的站点" v-model="model.siteid" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceid" label="设备编号，用于标识信号所属的设备">
          <a-input placeholder="请输入设备编号，用于标识信号所属的设备" v-model="model.deviceid" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type" label="数据类型：Digital（数字量）、Analog（模拟量）">
          <a-input placeholder="请输入数据类型：Digital（数字量）、Analog（模拟量）" v-model="model.type" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signalname" label="信号名称，用于描述信号的名称">
          <a-input placeholder="请输入信号名称，用于描述信号的名称" v-model="model.signalname" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alarmlevel" label="告警等级：None（无告警）、Low（低告警）、Medium（中告警）、High（高告警）、Critical（严重告警）">
          <a-input placeholder="请输入告警等级：None（无告警）、Low（低告警）、Medium（中告警）、High（高告警）、Critical（严重告警）" v-model="model.alarmlevel" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storageperiod" label="存储周期（单位：小时）">
          <a-input placeholder="请输入存储周期（单位：小时）" v-model="model.storageperiod" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="absoluteval" label="绝对阈值，用于设置信号的绝对阈值">
          <a-input placeholder="请输入绝对阈值，用于设置信号的绝对阈值" v-model="model.absoluteval" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relativeval" label="百分比阈值，用于设置信号的百分比阈值">
          <a-input placeholder="请输入百分比阈值，用于设置信号的百分比阈值" v-model="model.relativeval" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hlimit" label="上限，用于设置信号的上限值">
          <a-input placeholder="请输入上限，用于设置信号的上限值" v-model="model.hlimit" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shlimit" label="过高上限，用于设置信号的过高上限值">
          <a-input placeholder="请输入过高上限，用于设置信号的过高上限值" v-model="model.shlimit" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="llimit" label="下限，用于设置信号的下限值">
          <a-input placeholder="请输入下限，用于设置信号的下限值" v-model="model.llimit" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="slimit" label="过低上限，用于设置信号的过低上限值">
          <a-input placeholder="请输入过低上限，用于设置信号的过低上限值" v-model="model.slimit" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="describe" label="描述信息，用于提供更多的信号描述信息">
          <a-input placeholder="请输入描述信息，用于提供更多的信号描述信息" v-model="model.describe" />
        </a-form-model-item>
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "MSignalModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        scid:[{ required: true, message: '请输入下级SCID，用于标识所属的监控中心!' }],
        siteid:[{ required: true, message: '请输入站点编号，用于标识信号所在的站点!' }],
        deviceid:[{ required: true, message: '请输入设备编号，用于标识信号所属的设备!' }],
        type:[{ required: true, message: '请输入数据类型：Digital（数字量）、Analog（模拟量）!' }],
        signalname:[{ required: true, message: '请输入信号名称，用于描述信号的名称!' }],
        },
        url: {
          add: "/c/mSignal/add",
          edit: "/c/mSignal/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>